﻿using Mapster;
using Rswl.Common.Core.User.Aggregate.ValueObject;
using System.Security.Claims;
using System.Text.Json.Serialization;

namespace Rswl.Common.Application.User.Dto
{
    public class UserInfoDto
    {
        [JsonPropertyName("user_id")]
        public string UserId { get; set; } = "";
        [JsonPropertyName("user_name")]
        public string UserName { get; set; } = "";
        [JsonPropertyName("registerDate")]
        public DateTime RegisterDate { get; set; }
        [JsonPropertyName("register_date")]
        public string RegisterDateText { get { return RegisterDate.ToString("yyyy-MM-dd HH:mm:ss"); } }

        [JsonPropertyName("role")]
        public UserRole Role { get; set; }
        [JsonPropertyName("role_name")]
        public string RoleText { get { return Role.ToDescription(); } }
        [JsonPropertyName("user_roles")]
        public string[] Roles {
            get { 
                if(!string.IsNullOrWhiteSpace(UserRoles))
                {
                   return UserRoles.Split(",");
                }else
                {
                    return new string[0];
                }
            } 
        }
      
        public string UserRoles { get; set; }
        [JsonPropertyName("is_admin")]
        public bool IsAdmin { get {
                if (Role == UserRole.Admin)
                    return true;
                return false;
            } }

        [JsonPropertyName("grade")]
        public int Grade { get; set; }
        [AdaptIgnore]
        [JsonPropertyName("grade_name")]
        public string GradeText { get {
                return "";
            } }

        [JsonPropertyName("vip_enddate")]
        public DateTime? VipEndDate { get; set; }

        string endStr = "";
        [AdaptIgnore]
        [JsonPropertyName("vip_endstr")]
        public string VipEndText { 
            get {
                //if(Grade==UserGrade.Member)
                //{
                //    endStr = "";
                //}else
                //{
                //    if (Grade == UserGrade.VIP5)
                //        endStr = "长期";
                //    else
                //    {
                //        if(VipEndDate!=null&&(DateTime)VipEndDate<DateTime.Now)
                //        {
                //            var dt = (DateTime)VipEndDate - DateTime.Now;
                //            endStr = $"己过期{dt.Days}天";
                //        }
                //        else
                //        {
                //            if(VipEndDate!=null)
                //            endStr= $"有效期至{((DateTime)VipEndDate).ToString("yyyy-MM-dd")}";
                //        }
                //    }
                //}
                
                return endStr;
            }
       
        }

        [JsonPropertyName("avatar")]
        public string Avatar { get; set; } = "";
        [JsonPropertyName("nick")]
        public string Nick { get; set; } = "";

        /// <summary>
        /// 推广码
        /// </summary>
        [JsonPropertyName("invite_code")]
        public string InviteCode { get; set; } = "";

        [AdaptIgnore]
        [JsonPropertyName("integral")]
        public int integral { get; set; }


        /// <summary>
        /// 累计返现
        /// </summary>
        [AdaptIgnore]
        [JsonPropertyName("widthdrawal_total")]
        public decimal WidthdrawalTotal { get; set; }

        /// <summary>
        /// 限制文件大小50M
        /// </summary> 
        [JsonPropertyName("file_size_limit")]
        public int FileSizeLimit { get; set; } = 50;

        //这个定义无效了
        [JsonPropertyName("friend_invite_code")]
        public string InviteUserId { get; set; } = "";

       
        [JsonPropertyName("openId")]
        public string OpenId { get; set; } = "";

        int discount = 0;

        [AdaptIgnore]
        [JsonPropertyName("shareInfo")]
        public ShareInfoDto ShareInfo { get; set; }

        [JsonPropertyName("phone")]
		public string Phone { get; set; } = "";
		[JsonPropertyName("true_name")]
		public string TrueName { get; set; } = "";

        [JsonPropertyName("status")]
        public int Status { get; set; }
    }
}
